<template>
    <div>
        <top-bar></top-bar>
        <left-bar :datas='data'></left-bar>
        <div class="main">
            <div class="main-mains">
                <div class="main-content">
                    <div class="main-mains-top">
                        问卷列表
                    </div>
                    <div class="screen clear">
                        <div class="fl" @click="screen()">筛选</div>
                    </div>
                    <div class="publicTable toLongTable">
                        <table class="head_table">
                            <tr>
                                <td width="5%">用户账号</td>
                                <td width='5%'>问卷名称</td>
                                <td width='12%'>所得积分</td>
                                <td width='7%'>对应任务单元</td>
                                <td width='8%'>所属项目</td>
                                <td width='8%'>答题分数</td>
                                <td width='12%'>答题时间</td>
                                <td width='12%'>操作</td>
                            </tr>
                        </table>
                        <el-scrollbar>
                            <table class="content_table">
                                <tr v-for="(item,index) in listData" :key="index" :class="{active:index%2==1}">
                                    <td width="5%">{{item.title}}</td>
                                    <td width='5%'>{{item.channel}}</td>
                                    <td width='12%'>{{item.content}}</td>
                                    <td width='7%'>{{item.active | activeType}}</td>
                                    <td width='8%'>{{item.starttime}}</td>
                                    <td width='8%'>{{item.expires}}</td>
                                    <td width='12%'>{{item.create_time | times}}</td>
                                    <td width='12%'>
                                        <span class="active">查看</span>
                                    </td>
                                </tr>
                            </table>
                        </el-scrollbar>
                    </div>
                    <div class="nodataTip" v-if="showNodataTip">
                        <i class="iconfont icon-zanwuneirong"></i>
                        <h5>暂无内容</h5>
                    </div>
                    <div class="orderBotom">
                        <div class="orderBotomRight">
                            <el-pagination @current-change="handleCurrentChange" :page-size="15" layout="total, prev, pager, next" :total='totalnum'>
                            </el-pagination>
                        </div>
                    </div>
                </div>
            </div>
            <div class="system-menban" v-if="search">
            </div>
            <div class="systemPopup" v-if="search">
                <div class="topTitle">
                    <span>新增项目任务</span>
                    <i class="el-icon-close system-icon" @click="hideSystemPopup"></i>
                </div>
                <div class="systemPopup-con">
                    <div class="systemPopup-cons clear">
                        <div class="fl">时间</div>
                        <div class="fl sel">
                            <el-date-picker v-model="time" value-format="yyyy-MM-dd" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                            </el-date-picker>
                        </div>
                    </div>
                    <div class="systemPopup-cons clear">
                        <div class="fl">关键词搜索</div>
                        <div class="fl sel">
                            <el-input placeholder="请输入问卷名称/所属项目名称/任务单元名称" v-model.trim="keyword" clearable>
                            </el-input>
                        </div>
                    </div>
                    <div class="systemPopup-btn clear">
                        <div class="fl" @click="searchs()">确认</div>
                        <div class="fl" @click="hideSystemPopup">取消</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>


<script>
import leftBar from "@/components/leftBar";
import topBar from "@/components/topBar";
import questionnaire from "@/api/questionnaire";
export default {
  components: {
    leftBar,
    topBar
  },
  data() {
    return {
      data: "questionnaire",
      pages: 1,
      listData: [],
      totalnum: 0,
      showNodataTip: false,
      search: false,
      time: "",
      keyword: ""
    };
  },
  methods: {
    getDetails(id) {
      this.$router.push("/questionDetails?id=" + id);
    },
    screen() {
      this.search = true;
    },
    hideSystemPopup() {
      this.search = false;
    },
    handleCurrentChange(val) {
      this.pages = val;
      this.getList();
    },
    searchs() {
      this.pages = 1;
      this.getList();
    },
    getList() {
      this.showNodataTip = false;
      let options = {};
      if (this.time == null || this.time == "") {
        options = {
          page: this.pages,
          keywords: this.keyword,
          sta_date: "",
          end_date: ""
        };
      } else {
        options = {
          page: this.pages,
          keywords: this.keyword,
          sta_date: this.time[0],
          end_date: this.time[1]
        };
      }
      questionnaire.answerList(options).then(res => {
        if (res.code == 1) {
          this.listData = res.data.list;
          this.totalnum = res.data.total;
          if (!res.data.total) {
            this.showNodataTip = true;
          }
        }
      });
    }
  },
  mounted() {
    this.getList();
  },
  filters: {
    activeType(val) {
      let type;
      if (val == 1) {
        type = "正常";
      } else if (val == 2) {
        type = "审核中";
      } else if (val == 3) {
        type = "已删除";
      } else if (val == 4) {
        type = "受限";
      }
      return type;
    },
    times(value) {
      var time = new Date(value * 1000);
      var month =
        time.getMonth() + 1 > 9
          ? time.getMonth() + 1
          : "0" + (time.getMonth() + 1);
      var data = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
      var hour = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
      var minutes =
        time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
      var second =
        time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
      var times =
        time.getFullYear() +
        "-" +
        month +
        "-" +
        data +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        second;
      return times;
    }
  }
};
</script>

<style>
</style>
